<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>APScheduler使用 | 课程简介</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../C07-APScheduler/FixStatistics.html" />
    
    
    <link rel="prev" href="../C07-APScheduler/index.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="7.1"
        data-chapter-title="APScheduler使用"
        data-filepath="C07-APScheduler/APSchedulerTutorial.md"
        data-basepath=".."
        data-revision="Mon May 27 2019 03:35:45 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        课程简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="C01-Introduction/index.html">
            
                
                    <a href="../C01-Introduction/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        项目介绍
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="C01-Introduction/AboutToutiaoWebVM.html">
            
                
                    <a href="../C01-Introduction/AboutToutiaoWebVM.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        ToutiaoWeb虚拟机使用说明
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="C01-Introduction/PycharmRemoteDevelop.html">
            
                
                    <a href="../C01-Introduction/PycharmRemoteDevelop.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        Pycharm远程开发
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="C01-Introduction/AboutProject.html">
            
                
                    <a href="../C01-Introduction/AboutProject.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        产品与开发
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="C02-Database/index.html">
            
                
                    <a href="../C02-Database/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        数据库
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="C02-Database/DatabaseDesign.html">
            
                
                    <a href="../C02-Database/DatabaseDesign.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        数据库设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="C02-Database/ORM.html">
            
                
                    <a href="../C02-Database/ORM.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        理解ORM
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="C02-Database/SQLAlchemyMapping.html">
            
                
                    <a href="../C02-Database/SQLAlchemyMapping.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        SQLAlchemy映射构建
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="C02-Database/SQLAlchemyOperations.html">
            
                
                    <a href="../C02-Database/SQLAlchemyOperations.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        SQLAlchemy操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="C02-Database/DatabaseTheory.html">
            
                
                    <a href="../C02-Database/DatabaseTheory.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        数据库理论
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="C02-Database/DistributedID.html">
            
                
                    <a href="../C02-Database/DistributedID.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        分布式ID
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="C02-Database/DatabaseOptimize.html">
            
                
                    <a href="../C02-Database/DatabaseOptimize.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        数据库优化
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="C02-Database/Redis.html">
            
                
                    <a href="../C02-Database/Redis.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        Redis
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="C03-Gitflow/index.html">
            
                
                    <a href="../C03-Gitflow/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        Git工作流
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="C03-Gitflow/Gitflow.html">
            
                
                    <a href="../C03-Gitflow/Gitflow.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        Gitflow
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="C03-Gitflow/AboutGit.html">
            
                
                    <a href="../C03-Gitflow/AboutGit.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        Git总结
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="C03-Gitflow/ProjectDirectory.html">
            
                
                    <a href="../C03-Gitflow/ProjectDirectory.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        工程目录
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="C03-Gitflow/DebugMethod.html">
            
                
                    <a href="../C03-Gitflow/DebugMethod.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        调试方法
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="C04-JWT/index.html">
            
                
                    <a href="../C04-JWT/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        JWT
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="C04-JWT/JWT.html">
            
                
                    <a href="../C04-JWT/JWT.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        JWT &amp; JWS &amp; JWE
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="C04-JWT/PythonLib.html">
            
                
                    <a href="../C04-JWT/PythonLib.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        PythonLib
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="C04-JWT/Implement.html">
            
                
                    <a href="../C04-JWT/Implement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        实施方案
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="C04-JWT/Forbbiden.html">
            
                
                    <a href="../C04-JWT/Forbbiden.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        禁用问题
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="C05-OSS/index.html">
            
                
                    <a href="../C05-OSS/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        对象存储
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="C05-OSS/Qiniu.html">
            
                
                    <a href="../C05-OSS/Qiniu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        七牛云存储
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="C05-OSS/CDN.html">
            
                
                    <a href="../C05-OSS/CDN.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        CDN
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="C06-Cache/index.html">
            
                
                    <a href="../C06-Cache/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        缓存
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="C06-Cache/CacheArchitecture.html">
            
                
                    <a href="../C06-Cache/CacheArchitecture.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        缓存的架构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="C06-Cache/CacheData.html">
            
                
                    <a href="../C06-Cache/CacheData.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        缓存的数据
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="C06-Cache/CacheTTLAndEviction.html">
            
                
                    <a href="../C06-Cache/CacheTTLAndEviction.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        缓存的有效期与淘汰策略
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="C06-Cache/CachePatterns.html">
            
                
                    <a href="../C06-Cache/CachePatterns.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        缓存模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="C06-Cache/CacheProblems.html">
            
                
                    <a href="../C06-Cache/CacheProblems.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        缓存问题
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="C06-Cache/ProjectCacheAndStorageDesign.html">
            
                
                    <a href="../C06-Cache/ProjectCacheAndStorageDesign.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.6.</b>
                        
                        项目缓存与Redis持久存储设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.7" data-path="C06-Cache/ProjectCacheImplement.html">
            
                
                    <a href="../C06-Cache/ProjectCacheImplement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.7.</b>
                        
                        项目缓存实现
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.8" data-path="C06-Cache/ProjectRedisStorageImplement.html">
            
                
                    <a href="../C06-Cache/ProjectRedisStorageImplement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.8.</b>
                        
                        项目Redis持久存储实现
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="C07-APScheduler/index.html">
            
                
                    <a href="../C07-APScheduler/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        APScheduler
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="7.1" data-path="C07-APScheduler/APSchedulerTutorial.html">
            
                
                    <a href="../C07-APScheduler/APSchedulerTutorial.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        APScheduler使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="C07-APScheduler/FixStatistics.html">
            
                
                    <a href="../C07-APScheduler/FixStatistics.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        定时修正统计数据
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8" data-path="C08-RPC/index.html">
            
                
                    <a href="../C08-RPC/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        RPC
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.1" data-path="C08-RPC/AboutRPC.html">
            
                
                    <a href="../C08-RPC/AboutRPC.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.1.</b>
                        
                        RPC简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="C08-RPC/gRPC.html">
            
                
                    <a href="../C08-RPC/gRPC.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.2.</b>
                        
                        gRPC
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="C08-RPC/ProtocolBuffers.html">
            
                
                    <a href="../C08-RPC/ProtocolBuffers.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.3.</b>
                        
                        Protocol Buffers
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.4" data-path="C08-RPC/RecoSysIDL.html">
            
                
                    <a href="../C08-RPC/RecoSysIDL.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.4.</b>
                        
                        推荐系统接口定义
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.5" data-path="C08-RPC/Server.html">
            
                
                    <a href="../C08-RPC/Server.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.5.</b>
                        
                        服务端
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.6" data-path="C08-RPC/Client.html">
            
                
                    <a href="../C08-RPC/Client.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.6.</b>
                        
                        客户端
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.7" data-path="C08-RPC/ToutiaoAPIViewImplement.html">
            
                
                    <a href="../C08-RPC/ToutiaoAPIViewImplement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.7.</b>
                        
                        头条首页新闻推荐接口编写
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="9" data-path="C09-IM/index.html">
            
                
                    <a href="../C09-IM/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.</b>
                        
                        即时通信
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="9.1" data-path="C09-IM/AboutIM.html">
            
                
                    <a href="../C09-IM/AboutIM.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.1.</b>
                        
                        即时通信简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="C09-IM/WebSocket.html">
            
                
                    <a href="../C09-IM/WebSocket.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.2.</b>
                        
                        WebSocket
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.3" data-path="C09-IM/SocketIO.html">
            
                
                    <a href="../C09-IM/SocketIO.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.3.</b>
                        
                        Socket.IO
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.4" data-path="C09-IM/Chat.html">
            
                
                    <a href="../C09-IM/Chat.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.4.</b>
                        
                        头条聊天服务实现
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.5" data-path="C09-IM/MessagePush.html">
            
                
                    <a href="../C09-IM/MessagePush.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.5.</b>
                        
                        头条在线消息推送实现
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="10" data-path="C10-Elasticsearch/index.html">
            
                
                    <a href="../C10-Elasticsearch/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        Elasticsearch
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="10.1" data-path="C10-Elasticsearch/Introduction.html">
            
                
                    <a href="../C10-Elasticsearch/Introduction.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.1.</b>
                        
                        简介与原理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.2" data-path="C10-Elasticsearch/ConceptAndCluster.html">
            
                
                    <a href="../C10-Elasticsearch/ConceptAndCluster.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.2.</b>
                        
                        概念与集群
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.3" data-path="C10-Elasticsearch/AnalysisIK.html">
            
                
                    <a href="../C10-Elasticsearch/AnalysisIK.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.3.</b>
                        
                        IK中文分析器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.4" data-path="C10-Elasticsearch/IndexAndType.html">
            
                
                    <a href="../C10-Elasticsearch/IndexAndType.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.4.</b>
                        
                        索引与类型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.5" data-path="C10-Elasticsearch/Document.html">
            
                
                    <a href="../C10-Elasticsearch/Document.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.5.</b>
                        
                        文档
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.6" data-path="C10-Elasticsearch/Logstash.html">
            
                
                    <a href="../C10-Elasticsearch/Logstash.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.6.</b>
                        
                        Logstash导入数据
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.7" data-path="C10-Elasticsearch/Query.html">
            
                
                    <a href="../C10-Elasticsearch/Query.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.7.</b>
                        
                        查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.8" data-path="C10-Elasticsearch/ToutiaoSearchImplement.html">
            
                
                    <a href="../C10-Elasticsearch/ToutiaoSearchImplement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.8.</b>
                        
                        头条全文检索实现
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.9" data-path="C10-Elasticsearch/Suggest.html">
            
                
                    <a href="../C10-Elasticsearch/Suggest.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.9.</b>
                        
                        suggest查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.10" data-path="C10-Elasticsearch/ToutiaoSuggestImplement.html">
            
                
                    <a href="../C10-Elasticsearch/ToutiaoSuggestImplement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.10.</b>
                        
                        头条suggest查询实现
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="11" data-path="C11-Unittest.html">
            
                
                    <a href="../C11-Unittest.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.</b>
                        
                        单元测试
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12" data-path="C12-Deployment/index.html">
            
                
                    <a href="../C12-Deployment/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.</b>
                        
                        部署相关
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="12.1" data-path="C12-Deployment/Gunicorn.html">
            
                
                    <a href="../C12-Deployment/Gunicorn.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.1.</b>
                        
                        Gunicorn
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.2" data-path="C12-Deployment/Supervisor.html">
            
                
                    <a href="../C12-Deployment/Supervisor.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.2.</b>
                        
                        Supervisor
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >课程简介</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="apscheduler&#x4F7F;&#x7528;">APScheduler&#x4F7F;&#x7528;</h1>
<p>APScheduler &#xFF08;advanceded python scheduler&#xFF09;&#x662F;&#x4E00;&#x6B3E;Python&#x5F00;&#x53D1;&#x7684;&#x5B9A;&#x65F6;&#x4EFB;&#x52A1;&#x5DE5;&#x5177;&#x3002;</p>
<p>&#x6587;&#x6863;&#x5730;&#x5740; <a href="https://apscheduler.readthedocs.io/en/latest/userguide.html#starting-the-scheduler" target="_blank">https://apscheduler.readthedocs.io/en/latest/userguide.html#starting-the-scheduler</a></p>
<p>&#x7279;&#x70B9;&#xFF1A;</p>
<ul>
<li><p>&#x4E0D;&#x4F9D;&#x8D56;&#x4E8E;Linux&#x7CFB;&#x7EDF;&#x7684;crontab&#x7CFB;&#x7EDF;&#x5B9A;&#x65F6;&#xFF0C;&#x72EC;&#x7ACB;&#x8FD0;&#x884C;</p>
</li>
<li><p>&#x53EF;&#x4EE5;&#x52A8;&#x6001;&#x6DFB;&#x52A0;&#x65B0;&#x7684;&#x5B9A;&#x65F6;&#x4EFB;&#x52A1;&#xFF0C;&#x5982;</p>
<p>  &#x4E0B;&#x5355;&#x540E;30&#x5206;&#x949F;&#x5185;&#x5FC5;&#x987B;&#x652F;&#x4ED8;&#xFF0C;&#x5426;&#x5219;&#x53D6;&#x6D88;&#x8BA2;&#x5355;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x501F;&#x52A9;&#x6B64;&#x5DE5;&#x5177;&#xFF08;&#x6BCF;&#x4E0B;&#x4E00;&#x5355;&#x5C31;&#x8981;&#x6DFB;&#x52A0;&#x6B64;&#x8BA2;&#x5355;&#x7684;&#x5B9A;&#x65F6;&#x4EFB;&#x52A1;&#xFF09;</p>
</li>
<li><p>&#x5BF9;&#x6DFB;&#x52A0;&#x7684;&#x5B9A;&#x65F6;&#x4EFB;&#x52A1;&#x53EF;&#x4EE5;&#x505A;&#x6301;&#x4E45;&#x4FDD;&#x5B58;</p>
</li>
</ul>
<h3 id="1--&#x5B89;&#x88C5;">1  &#x5B89;&#x88C5;</h3>
<pre><code class="lang-shell">pip install apscheduler
</code></pre>
<h3 id="2--&#x4F7F;&#x7528;&#x65B9;&#x5F0F;">2  &#x4F7F;&#x7528;&#x65B9;&#x5F0F;</h3>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> apscheduler.schedulers.background <span class="hljs-keyword">import</span> BackgroundScheduler

<span class="hljs-comment"># &#x521B;&#x5EFA;&#x5B9A;&#x65F6;&#x4EFB;&#x52A1;&#x7684;&#x8C03;&#x5EA6;&#x5668;&#x5BF9;&#x8C61;</span>
scheduler = BackgroundScheduler()

<span class="hljs-comment"># &#x5B9A;&#x4E49;&#x5B9A;&#x65F6;&#x4EFB;&#x52A1;</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">my_job</span><span class="hljs-params">(param1, param2)</span>:</span>
    <span class="hljs-keyword">pass</span>

<span class="hljs-comment"># &#x5411;&#x8C03;&#x5EA6;&#x5668;&#x4E2D;&#x6DFB;&#x52A0;&#x5B9A;&#x65F6;&#x4EFB;&#x52A1;</span>
scheduler.add_job(my_job, <span class="hljs-string">&apos;date&apos;</span>, args=[<span class="hljs-number">100</span>, <span class="hljs-string">&apos;python&apos;</span>])

<span class="hljs-comment"># &#x542F;&#x52A8;&#x5B9A;&#x65F6;&#x4EFB;&#x52A1;&#x8C03;&#x5EA6;&#x5668;&#x5DE5;&#x4F5C;</span>
scheduler.start()
</code></pre>
<h3 id="3--&#x8C03;&#x5EA6;&#x5668;-scheduler">3  &#x8C03;&#x5EA6;&#x5668; Scheduler</h3>
<p>&#x8D1F;&#x8D23;&#x7BA1;&#x7406;&#x5B9A;&#x65F6;&#x4EFB;&#x52A1;</p>
<ul>
<li><p><code>BlockingScheduler</code>:  &#x4F5C;&#x4E3A;&#x72EC;&#x7ACB;&#x8FDB;&#x7A0B;&#x65F6;&#x4F7F;&#x7528;</p>
<pre><code class="lang-python">  <span class="hljs-keyword">from</span> apscheduler.schedulers.blocking <span class="hljs-keyword">import</span> BlockingScheduler

  scheduler = BlockingScheduler()
  scheduler.start()  <span class="hljs-comment"># &#x6B64;&#x5904;&#x7A0B;&#x5E8F;&#x4F1A;&#x53D1;&#x751F;&#x963B;&#x585E;</span>
</code></pre>
</li>
<li><p><code>BackgroundScheduler</code>:  &#x5728;&#x6846;&#x67B6;&#x7A0B;&#x5E8F;&#xFF08;&#x5982;Django&#x3001;Flask&#xFF09;&#x4E2D;&#x4F7F;&#x7528;</p>
<pre><code class="lang-python">  <span class="hljs-keyword">from</span> apscheduler.schedulers.background <span class="hljs-keyword">import</span> BackgroundScheduler

  scheduler = BackgroundScheduler()
  scheduler.start()  <span class="hljs-comment"># &#x6B64;&#x5904;&#x7A0B;&#x5E8F;&#x4E0D;&#x4F1A;&#x53D1;&#x751F;&#x963B;&#x585E;</span>
</code></pre>
</li>
</ul>
<h3 id="4--&#x6267;&#x884C;&#x5668;-executors">4  &#x6267;&#x884C;&#x5668; executors</h3>
<p>&#x5728;&#x5B9A;&#x65F6;&#x4EFB;&#x52A1;&#x8BE5;&#x6267;&#x884C;&#x65F6;&#xFF0C;&#x4EE5;&#x8FDB;&#x7A0B;&#x6216;&#x7EBF;&#x7A0B;&#x65B9;&#x5F0F;&#x6267;&#x884C;&#x4EFB;&#x52A1;</p>
<ul>
<li><p>ThreadPoolExecutor</p>
<pre><code class="lang-python">  <span class="hljs-keyword">from</span> apscheduler.executors.pool <span class="hljs-keyword">import</span> ThreadPoolExecutor
  ThreadPoolExecutor(max_workers)  
  ThreadPoolExecutor(<span class="hljs-number">20</span>) <span class="hljs-comment"># &#x6700;&#x591A;20&#x4E2A;&#x7EBF;&#x7A0B;&#x540C;&#x65F6;&#x6267;&#x884C;</span>
</code></pre>
<p>  &#x4F7F;&#x7528;&#x65B9;&#x6CD5;</p>
<pre><code class="lang-python">  executors = {
      <span class="hljs-string">&apos;default&apos;</span>: ThreadPoolExecutor(<span class="hljs-number">20</span>)
  }
  scheduler = BackgroundScheduler(executors=executors)
</code></pre>
</li>
<li><p>ProcessPoolExecutor</p>
<pre><code class="lang-python">  <span class="hljs-keyword">from</span> apscheduler.executors.pool <span class="hljs-keyword">import</span> ProcessPoolExecutor
  ProcessPoolExecutor(max_workers)
  ProcessPoolExecutor(<span class="hljs-number">5</span>) <span class="hljs-comment"># &#x6700;&#x591A;5&#x4E2A;&#x8FDB;&#x7A0B;&#x540C;&#x65F6;&#x6267;&#x884C;</span>
</code></pre>
<p>  &#x4F7F;&#x7528;&#x65B9;&#x6CD5;</p>
<pre><code class="lang-python">  executors = {
      <span class="hljs-string">&apos;default&apos;</span>: ProcessPoolExecutor(<span class="hljs-number">3</span>)
  }
  scheduler = BackgroundScheduler(executors=executors)
</code></pre>
</li>
</ul>
<h3 id="5-&#x89E6;&#x53D1;&#x5668;-trigger">5 &#x89E6;&#x53D1;&#x5668; Trigger</h3>
<p>&#x6307;&#x5B9A;&#x5B9A;&#x65F6;&#x4EFB;&#x52A1;&#x6267;&#x884C;&#x7684;&#x65F6;&#x673A;</p>
<h4 id="1&#xFF09;-date-&#x5728;&#x7279;&#x5B9A;&#x7684;&#x65F6;&#x95F4;&#x65E5;&#x671F;&#x6267;&#x884C;">1&#xFF09; date &#x5728;&#x7279;&#x5B9A;&#x7684;&#x65F6;&#x95F4;&#x65E5;&#x671F;&#x6267;&#x884C;</h4>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> datetime <span class="hljs-keyword">import</span> date

<span class="hljs-comment"># &#x5728;2019&#x5E74;11&#x6708;6&#x65E5;00:00:00&#x6267;&#x884C;</span>
sched.add_job(my_job, <span class="hljs-string">&apos;date&apos;</span>, run_date=date(<span class="hljs-number">2009</span>, <span class="hljs-number">11</span>, <span class="hljs-number">6</span>))

<span class="hljs-comment"># &#x5728;2019&#x5E74;11&#x6708;6&#x65E5;16:30:05</span>
sched.add_job(my_job, <span class="hljs-string">&apos;date&apos;</span>, run_date=datetime(<span class="hljs-number">2009</span>, <span class="hljs-number">11</span>, <span class="hljs-number">6</span>, <span class="hljs-number">16</span>, <span class="hljs-number">30</span>, <span class="hljs-number">5</span>))
sched.add_job(my_job, <span class="hljs-string">&apos;date&apos;</span>, run_date=<span class="hljs-string">&apos;2009-11-06 16:30:05&apos;</span>)

<span class="hljs-comment"># &#x7ACB;&#x5373;&#x6267;&#x884C;</span>
sched.add_job(my_job, <span class="hljs-string">&apos;date&apos;</span>)  
sched.start()
</code></pre>
<h4 id="2&#xFF09;-interval-&#x7ECF;&#x8FC7;&#x6307;&#x5B9A;&#x7684;&#x65F6;&#x95F4;&#x95F4;&#x9694;&#x6267;&#x884C;">2&#xFF09; interval &#x7ECF;&#x8FC7;&#x6307;&#x5B9A;&#x7684;&#x65F6;&#x95F4;&#x95F4;&#x9694;&#x6267;&#x884C;</h4>
<ul>
<li><strong>weeks</strong> (<em>int</em>) &#x2013; number of weeks to wait</li>
<li><strong>days</strong> (<em>int</em>) &#x2013; number of days to wait</li>
<li><strong>hours</strong> (<em>int</em>) &#x2013; number of hours to wait</li>
<li><strong>minutes</strong> (<em>int</em>) &#x2013; number of minutes to wait</li>
<li><strong>seconds</strong> (<em>int</em>) &#x2013; number of seconds to wait</li>
<li><strong>start_date</strong> (<em>datetime|str</em>) &#x2013; starting point for the interval calculation</li>
<li><strong>end_date</strong> (<em>datetime|str</em>) &#x2013; latest possible date/time to trigger on</li>
<li><strong>timezone</strong> (<em>datetime.tzinfo|str</em>) &#x2013; time zone to use for the date/time calculations</li>
</ul>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> datetime <span class="hljs-keyword">import</span> datetime

<span class="hljs-comment"># &#x6BCF;&#x4E24;&#x5C0F;&#x65F6;&#x6267;&#x884C;&#x4E00;&#x6B21;</span>
sched.add_job(job_function, <span class="hljs-string">&apos;interval&apos;</span>, hours=<span class="hljs-number">2</span>)

<span class="hljs-comment"># &#x5728;2010&#x5E74;10&#x6708;10&#x65E5;09:30:00 &#x5230;2014&#x5E74;6&#x6708;15&#x65E5;&#x7684;&#x65F6;&#x95F4;&#x5185;&#xFF0C;&#x6BCF;&#x4E24;&#x5C0F;&#x65F6;&#x6267;&#x884C;&#x4E00;&#x6B21;</span>
sched.add_job(job_function, <span class="hljs-string">&apos;interval&apos;</span>, hours=<span class="hljs-number">2</span>, start_date=<span class="hljs-string">&apos;2010-10-10 09:30:00&apos;</span>, end_date=<span class="hljs-string">&apos;2014-06-15 11:00:00&apos;</span>)
</code></pre>
<h4 id="3&#xFF09;-cron-&#x6309;&#x6307;&#x5B9A;&#x7684;&#x5468;&#x671F;&#x6267;&#x884C;">3&#xFF09; cron &#x6309;&#x6307;&#x5B9A;&#x7684;&#x5468;&#x671F;&#x6267;&#x884C;</h4>
<ul>
<li><strong>year</strong> (<em>int|str</em>) &#x2013; 4-digit year</li>
<li><strong>month</strong> (<em>int|str</em>) &#x2013; month (1-12)</li>
<li><strong>day</strong> (<em>int|str</em>) &#x2013; day of the (1-31)</li>
<li><strong>week</strong> (<em>int|str</em>) &#x2013; ISO week (1-53)</li>
<li><strong>day_of_week</strong> (<em>int|str</em>) &#x2013; number or name of weekday (0-6 or mon,tue,wed,thu,fri,sat,sun)</li>
<li><strong>hour</strong> (<em>int|str</em>) &#x2013; hour (0-23)</li>
<li><strong>minute</strong> (<em>int|str</em>) &#x2013; minute (0-59)</li>
<li><strong>second</strong> (<em>int|str</em>) &#x2013; second (0-59)</li>
<li><strong>start_date</strong> (<em>datetime|str</em>) &#x2013; earliest possible date/time to trigger on (inclusive)</li>
<li><strong>end_date</strong> (<em>datetime|str</em>) &#x2013; latest possible date/time to trigger on (inclusive)</li>
<li><strong>timezone</strong> (<em>datetime.tzinfo|str</em>) &#x2013; time zone to use for the date/time calculations (defaults to scheduler timezone)</li>
</ul>
<pre><code class="lang-python"><span class="hljs-comment"># &#x5728;6&#x3001;7&#x3001;8&#x3001;11&#x3001;12&#x6708;&#x7684;&#x7B2C;&#x4E09;&#x4E2A;&#x5468;&#x4E94;&#x7684;00:00, 01:00, 02:00&#x548C;03:00 &#x6267;&#x884C;</span>
sched.add_job(job_function, <span class="hljs-string">&apos;cron&apos;</span>, month=<span class="hljs-string">&apos;6-8,11-12&apos;</span>, day=<span class="hljs-string">&apos;3rd fri&apos;</span>, hour=<span class="hljs-string">&apos;0-3&apos;</span>)

<span class="hljs-comment"># &#x5728;2014&#x5E74;5&#x6708;30&#x65E5;&#x524D;&#x7684;&#x5468;&#x4E00;&#x5230;&#x5468;&#x4E94;&#x7684;5:30&#x6267;&#x884C;</span>
sched.add_job(job_function, <span class="hljs-string">&apos;cron&apos;</span>, day_of_week=<span class="hljs-string">&apos;mon-fri&apos;</span>, hour=<span class="hljs-number">5</span>, minute=<span class="hljs-number">30</span>, end_date=<span class="hljs-string">&apos;2014-05-30&apos;</span>)
</code></pre>
<h3 id="6--&#x914D;&#x7F6E;&#x65B9;&#x6CD5;">6  &#x914D;&#x7F6E;&#x65B9;&#x6CD5;</h3>
<h4 id="&#x65B9;&#x6CD5;1">&#x65B9;&#x6CD5;1</h4>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> apscheduler.schedulers.background <span class="hljs-keyword">import</span> BackgroundScheduler
<span class="hljs-keyword">from</span> apscheduler.executors.pool <span class="hljs-keyword">import</span> ThreadPoolExecutor

executors = {
    <span class="hljs-string">&apos;default&apos;</span>: ThreadPoolExecutor(<span class="hljs-number">20</span>),
}
scheduler = BackgroundScheduler(executors=executors)
</code></pre>
<h4 id="&#x65B9;&#x6CD5;2">&#x65B9;&#x6CD5;2</h4>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> pytz <span class="hljs-keyword">import</span> utc

<span class="hljs-keyword">from</span> apscheduler.schedulers.background <span class="hljs-keyword">import</span> BackgroundScheduler
<span class="hljs-keyword">from</span> apscheduler.jobstores.sqlalchemy <span class="hljs-keyword">import</span> SQLAlchemyJobStore
<span class="hljs-keyword">from</span> apscheduler.executors.pool <span class="hljs-keyword">import</span> ProcessPoolExecutor

executors = {
    <span class="hljs-string">&apos;default&apos;</span>: {<span class="hljs-string">&apos;type&apos;</span>: <span class="hljs-string">&apos;threadpool&apos;</span>, <span class="hljs-string">&apos;max_workers&apos;</span>: <span class="hljs-number">20</span>},
    <span class="hljs-string">&apos;processpool&apos;</span>: ProcessPoolExecutor(max_workers=<span class="hljs-number">5</span>)
}

scheduler = BackgroundScheduler()

<span class="hljs-comment"># .. &#x6B64;&#x5904;&#x53EF;&#x4EE5;&#x7F16;&#x5199;&#x5176;&#x4ED6;&#x4EE3;&#x7801;</span>

<span class="hljs-comment"># &#x4F7F;&#x7528;configure&#x65B9;&#x6CD5;&#x8FDB;&#x884C;&#x914D;&#x7F6E;</span>
scheduler.configure(executors=executors)
</code></pre>
<h3 id="7-&#x542F;&#x52A8;">7 &#x542F;&#x52A8;</h3>
<pre><code class="lang-python">scheduler.start()
</code></pre>
<ul>
<li>&#x5BF9;&#x4E8E;BlockingScheduler &#xFF0C;&#x7A0B;&#x5E8F;&#x4F1A;&#x963B;&#x585E;&#x5728;&#x8FD9;&#xFF0C;&#x9632;&#x6B62;&#x9000;&#x51FA;</li>
<li>&#x5BF9;&#x4E8E;BackgroundScheduler&#xFF0C;&#x7A0B;&#x5E8F;&#x4F1A;&#x7ACB;&#x5373;&#x8FD4;&#x56DE;&#xFF0C;&#x540E;&#x53F0;&#x8FD0;&#x884C;</li>
</ul>
<h3 id="8-&#x6269;&#x5C55;">8 &#x6269;&#x5C55;</h3>
<h4 id="&#x4EFB;&#x52A1;&#x7BA1;&#x7406;">&#x4EFB;&#x52A1;&#x7BA1;&#x7406;</h4>
<p>&#x65B9;&#x5F0F;1</p>
<pre><code class="lang-python">job = scheduler.add_job(myfunc, <span class="hljs-string">&apos;interval&apos;</span>, minutes=<span class="hljs-number">2</span>)  <span class="hljs-comment"># &#x6DFB;&#x52A0;&#x4EFB;&#x52A1;</span>
job.remove()  <span class="hljs-comment"># &#x5220;&#x9664;&#x4EFB;&#x52A1;</span>
job.pause() <span class="hljs-comment"># &#x6682;&#x5B9A;&#x4EFB;&#x52A1;</span>
job.resume()  <span class="hljs-comment"># &#x6062;&#x590D;&#x4EFB;&#x52A1;</span>
</code></pre>
<p>&#x65B9;&#x5F0F;2</p>
<pre><code class="lang-python">scheduler.add_job(myfunc, <span class="hljs-string">&apos;interval&apos;</span>, minutes=<span class="hljs-number">2</span>, id=<span class="hljs-string">&apos;my_job_id&apos;</span>)  <span class="hljs-comment"># &#x6DFB;&#x52A0;&#x4EFB;&#x52A1;    </span>
scheduler.remove_job(<span class="hljs-string">&apos;my_job_id&apos;</span>)  <span class="hljs-comment"># &#x5220;&#x9664;&#x4EFB;&#x52A1;</span>
scheduler.pause_job(<span class="hljs-string">&apos;my_job_id&apos;</span>)  <span class="hljs-comment"># &#x6682;&#x5B9A;&#x4EFB;&#x52A1;</span>
scheduler.resume_job(<span class="hljs-string">&apos;my_job_id&apos;</span>)  <span class="hljs-comment"># &#x6062;&#x590D;&#x4EFB;&#x52A1;</span>
</code></pre>
<h4 id="&#x8C03;&#x6574;&#x4EFB;&#x52A1;&#x8C03;&#x5EA6;&#x5468;&#x671F;">&#x8C03;&#x6574;&#x4EFB;&#x52A1;&#x8C03;&#x5EA6;&#x5468;&#x671F;</h4>
<pre><code class="lang-python">job.modify(max_instances=<span class="hljs-number">6</span>, name=<span class="hljs-string">&apos;Alternate name&apos;</span>)

scheduler.reschedule_job(<span class="hljs-string">&apos;my_job_id&apos;</span>, trigger=<span class="hljs-string">&apos;cron&apos;</span>, minute=<span class="hljs-string">&apos;*/5&apos;</span>)
</code></pre>
<h4 id="&#x505C;&#x6B62;apscheduler&#x8FD0;&#x884C;">&#x505C;&#x6B62;APScheduler&#x8FD0;&#x884C;</h4>
<pre><code class="lang-python">scheduler.shutdown()
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../C07-APScheduler/index.html" class="navigation navigation-prev " aria-label="Previous page: APScheduler"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../C07-APScheduler/FixStatistics.html" class="navigation navigation-next " aria-label="Next page: 定时修正统计数据"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
